package org.wiztools.gaewebtester;

import com.google.appengine.api.memcache.jsr107cache.GCacheFactory;
import java.util.HashMap;
import java.util.Map;
import javax.cache.Cache;
import javax.cache.CacheException;
import javax.cache.CacheFactory;
import javax.cache.CacheManager;

/**
 *
 * @author subwiz
 */
class CacheUtil {
    
    private static final Cache cache;
    
    public static final int TIMEOUT_SECONDS = 86400;
    public static final int TIMEOUT_HOURS = (TIMEOUT_SECONDS/60)/60;
    
    static {
        Map props = new HashMap();
        props.put(GCacheFactory.EXPIRATION_DELTA, TIMEOUT_SECONDS);
        
        try {
            CacheFactory cacheFactory = CacheManager.getInstance().getCacheFactory();
            cache = cacheFactory.createCache(props);
        }
        catch(CacheException ex) {
            throw new RuntimeException(ex);
        }
    }
    
    static void put(Object key, Object value) {
        cache.put(key, value);
    }
    
    static String get(Object key) {
        return (String) cache.get(key);
    }
}
